input_number = '-100'
input_number = int(input_number,10)
print(input_number)
d = {'Adam': 95, 'Lisa': 85, 'Bart': 59}
for key, item in d.items():
    print(key,':',item)


users = [
    {'name':'lz1','age':18},
    {'name':'lz2','age':21},
    {'name':'lz3','age':16},
    {'name':'lz4','age':20},
    {'name':'lz5','age':15},
]

def comp(x, y):
    print(x,y)
    if x[1] < y[1]:
        return 1
    elif x[1] > y[1]:
        return -1
    else:
        return 0
def comp1(x,y):
    return x[1] - y[1]
# print(sorted(users, key=lambda x: x['name'] ,reverse=True))
# print(users.sort(key=lambda user:user['age'] ,reverse=True))
print(users)
users.sort(key=lambda item:item['age'], reverse=True)
print(users)

# 复杂的dict，按照dict对象中某一个属性进行排序
lst = [{'level': 19, 'star': 36, 'time': 1},
       {'level': 20, 'star': 40, 'time': 2},
       {'level': 20, 'star': 40, 'time': 3},
       {'level': 20, 'star': 40, 'time': 4},
       {'level': 20, 'star': 40, 'time': 5},
       {'level': 18, 'star': 40, 'time': 1}]

# 先按time排序
# lst.sort(key=lambda k: (k.get('time', 0)))
print(lst)
# 再按照level和star顺序
# reverse=True表示反序排列，默认正序排列
lst.sort(key=lambda k: (k.get('level', 0), k.get('star', 0)), reverse=True)
print(lst)
for idx, r in enumerate(lst):
    print('idx[%d]\tlevel: %d\t star: %d\t time: %d\t' % (idx, r['level'],r['star'], r['time']))

# 简单的dict
lst = [('d', 2), ('a', 4), ('b', 3), ('c', 2)]

# 按照value排序
lst.sort(key=lambda k: k[1])
print(lst)

# 按照key排序
lst.sort(key=lambda k: k[0])
print(lst)

# 先按value排序再按key排序
lst.sort(key=lambda k: (k[1], k[0]))
print(lst)

# 输出---->>>
# [('d', 2), ('c', 2), ('b', 3), ('a', 4)]
# [('a', 4), ('b', 3), ('c', 2), ('d', 2)]
# [('c', 2), ('d', 2), ('b', 3), ('a', 4)]